package com.rain.service.orders;

import com.rain.persistence.orders.domain.OrdersDO;
import com.rain.persistence.orders.manager.OrdersManager;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * @author: wu
 * @date: 2021/4/4
 */
@Service
@Slf4j
public class OrdersService {

    @Autowired
    private OrdersManager ordersManager;


    @Transactional(rollbackFor = Exception.class)
    public Boolean saveOrder() {
        log.error("XID:{}", RootContext.getXID());
        OrdersDO ordersDO = new OrdersDO();
        ordersDO.setProductId(1);
        ordersDO.setAmount(100d);
        ordersDO.setCreateTime(LocalDateTime.now());
        ordersDO.setSum(1);
        ordersDO.setAccountId(1);
        ordersManager.save(ordersDO);
        return Boolean.TRUE;
    }
}
